import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
 * The item class makes reference to the diversity of items that exist on the game.
 * 
 * @author (Arturo Aaron Rios Obregon) 
 * @version (29 de junio)
 */
public class Item extends Actor
{
    Random rand = new Random();
    private static final int vel = 1;
    enum Direccion{DU,DD,IU,ID};
    Direccion dir;
    SimpleTimer timer;
    private int cantidad;
    /**
     * Create the item and give him a random direction , take the hour of creation.
     */
    public Item(int cant)
    {
        int op=Greenfoot.getRandomNumber(4);
        switch(op)
        {
            case 0: dir= Direccion.DU;
                    break;
            case 1: dir= Direccion.DD;
                    break;
            case 2: dir= Direccion.IU;
                    break;
            case 3: dir= Direccion.ID;
                    break;
        }
        timer = new SimpleTimer();
        timer.mark();
        cantidad=cant;
    }
    
    /**
     * This method return the amount of the item.
     */
    public int getCantidad()
    {
        return cantidad;
    }
    
    /**
     * This method eliminate the item after certain time.
     */
    public void eliminaTiempo()
    {
        if(timer.millisElapsed()/1000>7)
            getWorld().removeObject(this);
    }
    
    
    /**
     * Method who makes the move of the items.
     */
    public void mueve()
    {
        
        
        switch(dir)
        {
            case DD:
                    if(this.getY()<getWorld().getHeight()-1)
                        setLocation(this.getX()+vel,this.getY()+vel);
                    else
                        dir=Direccion.DU;
                    if(this.getX()<getWorld().getWidth()-1)
                        setLocation(this.getX()+vel,this.getY()+vel);
                    else
                        dir=Direccion.ID;
                    break;
            case DU:
                    if(this.getY()>0)
                        setLocation(this.getX()+vel,this.getY()-vel);
                    else
                        dir=Direccion.DD;
                    if(this.getX()<getWorld().getWidth()-1)
                        setLocation(this.getX()+vel,this.getY()-vel);
                    else
                        dir=Direccion.IU;
                    break;
            case ID:
                    if(this.getY()<getWorld().getHeight()-1)
                        setLocation(this.getX()-vel,this.getY()+vel);
                    else
                        dir=Direccion.IU;
                    if(this.getX()>0)
                        setLocation(this.getX()-vel,this.getY()+vel);
                    else
                        dir=Direccion.DD;
                    break;
            case IU:
                     if(this.getY()>0)
                        setLocation(this.getX()-vel,this.getY()-vel);
                     else
                        dir=Direccion.ID;
                     if(this.getX()>0)
                        setLocation(this.getX()-vel,this.getY()-vel);
                     else
                        dir=Direccion.DU;
                    break;
        }
               
    }
    
    
    
}
